package tools

import (
	"context"
	"fmt"

	"github.com/cloudwego/eino/components/tool"
	"github.com/cloudwego/eino/schema"
)

func GetQueryCurrentUserTool(backService *N9EService) tool.InvokableTool {
	return &ToolQueryCurrentUser{
		backService: backService,
	}
}

type ToolQueryCurrentUser struct {
	backService *N9EService
}

func (t *ToolQueryCurrentUser) Info(ctx context.Context) (*schema.ToolInfo, error) {

	toolInfo := &schema.ToolInfo{
		Name: "queryCurrentUser",
		Desc: "查询当前用户信息",
	}
	return toolInfo, nil
}

func (t *ToolQueryCurrentUser) InvokableRun(ctx context.Context, argumentsInJSON string, opts ...tool.Option) (string, error) {
	user, err := t.backService.GetUserProfile(ctx)

	if err != nil {
		return "", err
	}

	if user == nil {
		return "", fmt.Errorf("当前用户不存在")
	}

	return fmt.Sprintf("当前用户信息：%+v", user), nil
}
